

export const TOKEN_KEY = 'Authorization';
const MENUS_KEY = 'menus';
const USER_KEY = 'login_user'
const PERMS_KEY = 'perms'
export const REFRESH_TOKEN = "Refresh-Token";



export function getMenus(): API.Menus[] | undefined{
  const menusStr = sessionStorage.getItem(MENUS_KEY);
  if(menusStr){
    return  JSON.parse(menusStr) as API.Menus[]
  }
  return undefined;
}

export function setMenus(value: API.Menus[]): void{
  sessionStorage.setItem(MENUS_KEY,JSON.stringify(value));
}


export function removeMenus(){
  sessionStorage.removeItem(MENUS_KEY)
}



export function getUser(): API.User | undefined{
  const menusStr = sessionStorage.getItem(USER_KEY);
  if(menusStr){
    return  JSON.parse(menusStr) as API.User
  }
  return undefined;
}

export function setUser(value?: API.User): void{
  sessionStorage.setItem(USER_KEY,JSON.stringify(value));
}

export function removeUser(){
  sessionStorage.removeItem(USER_KEY)
}

export function setPermissions(value?: string[]): void{
  sessionStorage.setItem(PERMS_KEY,JSON.stringify(value));
}

export function getPermissions(): string[] | undefined{
  const menusStr = sessionStorage.getItem(PERMS_KEY);
  if(menusStr){
    return  JSON.parse(menusStr) as string[]
  }
  return undefined;
}

export function removePermissions(){
  sessionStorage.removeItem(PERMS_KEY)
}



export function getItem(key: string): string | null{
  return sessionStorage.getItem(key)
}

export function setItem(key: string,value: string): void{
  sessionStorage.setItem(key,value);
}

export function removeItem(key: string): void{
  sessionStorage.removeItem(key)
}

export function getToken(): string | null{
  return sessionStorage.getItem(TOKEN_KEY)
}

export function setToken(value: string): void{
  sessionStorage.setItem(TOKEN_KEY,value);
}

export function removeToke(): void{
  sessionStorage.removeItem(TOKEN_KEY)
}


